package day_2022_12_to_3.year2023;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * @author haomin
 * @date 2023/03/11 09:51
 **/
public class Day3_11_Offer1705 {
    class Solution {
        public String[] findLongestSubarray(String[] array) {
            Map<Integer, Integer> map = new HashMap<>();
            map.put(0, 0);
            int start = 0, end = 0, count = 0, n = array.length;
            for(int i = 0; i < n; ++i) {
                if(Character.isDigit(array[i].charAt(0)))
                    count++;
                else count--;
                if(map.containsKey(count)) {
                    int a = map.get(count);
                    if(i+1 - a > end - start) {
                        start = a;
                        end = i+1;
                    }
                }else map.put(count, i + 1);
            }
            return Arrays.copyOfRange(array, start, end);
        }
    }
}